<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>透明的单例类的编写优化版</title>
</head>
<body>
<button id="loginBtn">
    登陆
</button>
<script>
  var createLoginLayer = function () {
      var div = document.createElement('div');
      div.innerHTML = '我是登陆浮窗';
      div.style.display = 'none';
      document.body.appendChild(div);
      return div;
  }
  document.getElementById('loginBtn').onclick = function () {
      var loginLayer = createLoginLayer();
      loginLayer.style.display = 'block';
  }
</script>
</body>
</html>